package com.IR.product.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.IR.product.service.BProductBIZ;
import com.IR.shop.po.Product;


import net.sf.json.JSONArray;


/**
 * @author 单立鑫
 * @date 2018-09-05
 * */
@Controller
public class BProductAction {

	@Resource
	private BProductBIZ biz;
	
	/*查询下架商品*/
	@RequestMapping(value="/showProDown.do")
	public void showProDown(Integer pagenow,Integer pagesize) {
		List<Product> l=biz.showProDown(pagenow, pagesize);
		//测试部分
		for(Product p:l){
			System.out.println(p.getProsite());
		}
	}
	
	/*通过商品id查询所有信息*/
	@RequestMapping(value="/showProId.do")
	public void showProId(Long proid,HttpServletResponse response) {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		Product pro=new Product();
		pro=biz.showProId(proid);
		
		try {
			PrintWriter out = response.getWriter();
			String str=JSONArray.fromObject(pro).toString();
			out.println(str);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/*通过商品种类id查询商品*/
	@RequestMapping(value="/showProType.do")
	public void showProType(HttpServletRequest request,
			HttpServletResponse response) {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		Integer pagenow=new Integer(request.getParameter("pagenow"));
		Integer pagesize=new Integer(request.getParameter("pagesize"));
		int protypeid=new Integer(request.getParameter("protypeid"));
		List<Product> l=biz.showProType(pagenow,pagesize,protypeid);
		
		try {
			PrintWriter out = response.getWriter();
			String str=JSONArray.fromObject(l).toString();
			out.println(str);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		/*//测试所用
		System.out.println(l.size());
		for(Product p:l) {
			System.out.println(p.getProname());
		}*/
	}
	
	/*分页查询上架商品*/
	@RequestMapping(value="/showProPage.do")
	public void shoProPage(HttpServletRequest request,HttpServletResponse response) throws IOException {
		Integer pagenow=new Integer(request.getParameter("pagenow"));
		Integer pagesize=new Integer(request.getParameter("pagesize"));
		List<Product> l=biz.showProPage(pagenow,pagesize);
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		PrintWriter out=response.getWriter();
		String str=JSONArray.fromObject(l).toString();
		out.println(str);
	}


}
